home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / FDF101.ARJ / ELIB.ZOO / marks.c < prev   
C/C++ Source or Header  |  1992-04-30  |  1KB  |  56 lines

  1. #include <ctype.h>
  2. #include <stddef.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <dir.h>
  6.  
  7. #include "elib.h"
  8.  
  9.  
  10.  
  11. /*
  12.  * mark_list
  13.  *
  14.  * given a list of numbers (separated by commas with ranges specified by -'s),
  15.  * fill in the given character array with 0's for numbers not specified and
  16.  * 1's for numbers specified.  The size of the character array is also given.
  17.  * Return 0 on success, non-zero means failure, such as an out-of-range number
  18.  * in the given list.
  19.  */
  20. int mark_list(char *num_list, char *mark_list, int max_num)
  21.  
  22. {
  23.     char *cur_pos, *new_pos;
  24.     int i, j;
  25.  
  26.     for (i=0; i<max_num; i++)
  27.         mark_list[i] = '\0';
  28.  
  29.     for (cur_pos = num_list; *cur_pos != '\0'; cur_pos = ++new_pos) {
  30.         if (((i = (int) strtol(cur_pos, &new_pos, 10)) < 1) || (i > max_num) ||
  31.             (new_pos == NULL))
  32.             return 1;
  33.         
  34.         if (*(new_pos = skip_whitespace(new_pos)) == '-') {
  35.             cur_pos = new_pos+1;
  36.             if (((j = (int) strtol(cur_pos, &new_pos, 10)) < i) ||
  37.                 (j > max_num) || (new_pos == NULL))
  38.                 return 1;
  39.             for (i--, j--; i <= j; i++)
  40.                 mark_list[i] = '\1';
  41.         }
  42.         else if (*new_pos == ',')
  43.             mark_list[i-1] = '\1';
  44.         else if (*new_pos ==  '\0') {
  45.             mark_list[i-1] = '\1';
  46.             return 0;
  47.         }
  48.         else if (isdigit(*new_pos)) {
  49.             mark_list[i-1] = '\1';
  50.             new_pos--;
  51.         }
  52.     }
  53.  
  54.     return 0;
  55. }
  56.